JustTheBase = false
ScriptRoot = require('lin.utils').current_script_dir()
LazyRoot = vim.fn.stdpath('data') .. '/lazy/'

-- base part:

require('lin.base.edit-opts')
require('lin.base.autocmds')
require('lin.base.keymaps')
require('lin.base.commands')
require('lin.base.lsp-and-diag')
require('lin.base.neovide')

local rtd = ScriptRoot .. 'base/rtd'
if JustTheBase then
    vim.opt.rtp:append(rtd)
else
    -- plugin part:

    local lazypath = LazyRoot .. 'lazy.nvim'
    if not vim.uv.fs_stat(lazypath) then
        -- get lazy.nvim if not exist
        vim.fn.system({
            'git',
            'clone',
            '--filter=blob:none',
            'https://github.com/folke/lazy.nvim.git',
            '--branch=stable',
            lazypath,
        })
    end
    vim.opt.rtp:prepend(lazypath)

    -- Check https://github.com/neovim/neovim/issues/27230.
    -- In short, the markdown ftplugin includes the html one, which makes
    -- `match_words`, an option the plugin 'matchit' utilizes, include an
    -- item that essentially makes some '<...' the left part of a 'pair',
    -- so the '%' command would try to find the right part of this 'pair',
    -- ignoring any other 'pairs' inside of that '...'.
    -- `vim-matchup` could be an alternative.
    vim.g.loaded_matchit = 1
    vim.g.loaded_netrw = 1
    vim.g.loaded_netrwPlugin = 1

    require('lazy').setup('lin.plugs', {
        performance = {
            rtp = { paths = { rtd } }
        }
    })
    require('lin.plugs.conf.keymaps').setup_init_keymaps()
end

local colorscheme, dark = 'default', true
local f = io.open(ScriptRoot .. 'looks-good.conf', 'r')
if f then
    local conf = vim.json.decode(f:read('*a'))
    local hour = tonumber(os.date('%H'))
    if hour >= 6 and hour <= 17 then
        conf = conf.day
    else
        conf = conf.night
    end
    colorscheme, dark = conf.theme, conf.bg == 'dark'
    f:close()
end
require('lin.utils').looks(colorscheme, dark)
